/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Windows Forms Controls Class Library
 * Version 2.00
 * 
 * Color Modifier Class
 *		Provides static methods for modifying colors.
 *------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------------*/
using System;
using System.Drawing;

namespace Adaptive.Foundation.Windows.Forms
{
    /// <summary>
    /// Provides static methods for modifying colors.
    /// </summary>
    public static class ColorModifier
    {
        /*----------------------------------------------------------------------------------------------------
		 * Public Static / Shared Methods/Functions
		 *--------------------------------------------------------------------------------------------------*/
        #region Public Static / Shared Methods/Functions
        /// <summary>
        /// Makes the supplied color lighter by the specified amount.
        /// </summary>
        /// <param name="originalColor">
        /// The color value to be modified.
        /// </param>
        /// <param name="changeAmount">
        /// The amount (between 0 and 255) to modify the color.
        /// </param>
        /// <returns>
        /// The new <see cref="Color"/> structure.
        /// </returns>
        public static Color LightenColor(Color originalColor, int changeAmount)
        {
            Color returnValue;		//Return color.

            //Create new color.
            returnValue = Color.FromArgb(255,
                AdjustColorValue(originalColor.R, changeAmount),
                AdjustColorValue(originalColor.G, changeAmount),
                AdjustColorValue(originalColor.B, changeAmount));

            return returnValue;
        }
        /// <summary>
        /// Makes the supplied color darker by the specified amount.
        /// </summary>
        /// <param name="originalColor">
        /// The color value to be modified.
        /// </param>
        /// <param name="changeAmount">
        /// The amount (between 0 and 255) to modify the color.
        /// </param>
        /// <returns>
        /// The new <see cref="Color"/> structure.
        /// </returns>
        public static Color DarkenColor(Color originalColor, int changeAmount)
        {
            Color returnValue;		//Return color.

            //Modify parameter for darkening.
            changeAmount *= -1;

            //Create new color.
            returnValue = Color.FromArgb(255,
                AdjustColorValue(originalColor.R, changeAmount),
                AdjustColorValue(originalColor.G, changeAmount),
                AdjustColorValue(originalColor.B, changeAmount));

            return returnValue;
        }

        #endregion

        /*----------------------------------------------------------------------------------------------------
		 * Private Static / Shared Methods/Functions
		 *--------------------------------------------------------------------------------------------------*/
        #region Private Static / Shared Methods/Functions
        /// <summary>
        /// Adjusts the supplied color value with the specified change amount.
        /// </summary>
        /// <remarks>
        /// This method adds the change amount to the original, but ensures the 
        /// result is in the range 0-255.
        /// </remarks>
        /// <param name="original">The value to be modified.</param>
        /// <param name="changeAmount">The amount the original value is to be modified by.</param>
        /// <returns>
        /// The modified value in the range 0-255.
        /// </returns>
        private static int AdjustColorValue(int original, int changeAmount)
        {
            int returnValue = 0;		//Return value.

            returnValue = original + changeAmount;

            //Modify for exceeding bounds.
            if (returnValue < 0)
                returnValue = 0;
            else if (returnValue > 255)
                returnValue = 255;

            return returnValue;
        }
        #endregion
    }
}
